﻿@model IEnumerable<DSAAssignment.Models.CartModel>

@{
    ViewBag.Title = "ShoppingCart";
    Layout = "~/Views/Shared/_Layout.cshtml";
}

<script type="text/javascript">
    function OnSuccess() {
        alert("Item Purchased!")
    }

    function OnRemove() {
        alert("Item Removed!")
    }


    function OnFailure() {
        alert("Something went Wrong!!")
    }  
</script>


<h2>ShoppingCart</h2>
<table id="tblCart">
    <tr>
        <th>
            Image
        </th>
        <th>
            ProductName
        </th>
        <th>
            Quantity
        </th>
        <th></th>
    </tr>

@foreach (var item in Model) {
    <tr>   
        <td>
            <img src="@Html.DisplayFor(modelItem => item.Image)" alt="ProductImage" width="60px" height="60px" />
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.ProductName)
        </td>
        <td>
            @Html.DisplayFor(modelItem => item.Quantity)
        </td>
        <td>
            @Html.ActionLink("Details", "Details", new { id = item.ProductID }) |
            @Html.ActionLink("Delete", "RemoveProductFromCart", new { cartID = item.CartID }, new AjaxOptions() { UpdateTargetId = "tblCart", HttpMethod = "POST", OnSuccess = "OnRemove", OnFailure = "OnFailure", OnComplete = "OnRemove" })
        </td>
    </tr>
}
</table>

@using (Ajax.BeginForm("PlaceOrder","Product", new AjaxOptions() { HttpMethod = "POST", OnSuccess = "OnSuccess", OnComplete = "OnSuccess" }))
{
    <input id="BtnPurchase" type="submit" value="Purchase" />
}
